var lis=$(".title li");
var divs=$(".picVideo");
var result;

function setVideo(key){
	$(".keyword").text(key);
	$(".video").css("display","none");
	var url="/book/video";
	var params={keyWord:key};
	$.post(
		url,
		params,
		function(data){
			
//			alert(data.youku[0].title);
//			alert(data);
//			var jsonStr = JSON.stringify( obj );
			result=data;
			tab();
//			  alert(bToObj.youku[0].title);
//			$("videoContent div").text(data);


			
		},
		"json"
	);
	
}
function tab(){
	$(".video").css("display","block");
	if(lis.length!=divs.length){
		alert('lis:'+lis.length+"   divs:"+divs.length);
        return;
	}
    for(var i=0;i<lis.length;i++){
        lis[i].className="";
        divs[i].style.display="none";
    }
   
	if(result.wangyi==null){
		alert("对不起，网易公开课目前还没收录相关视频");
		lis[0].className='select';
	}else{
		var imgs=$("#wangyiVideo img");
		var ps=$("#wangyiVideo p");
		var as=$(".link0");
//		alert(result.wangyi.length);
//		alert(result.wangyi[0].picUrl);
		for(var i=0;i<result.wangyi.length;i++){
			   imgs[i].src=result.wangyi[i].picUrl;
			   imgs[i].style.display="block";
			   as[i].href=result.wangyi[i].videoUrl;
			   as[i].target="_blank";
			   ps[i].innerHTML="<a href=\""+result.wangyi[i].videoUrl
			   +"\"  target=\"_blank\">"+result.wangyi[i].title+"</a>";
			  
		   }
		
	    lis[0].className="select";
	    divs[0].style.display="block";
	    for(var i=i;i<4;i++){
	    	imgs[i].style.display="none";
	    	ps[i].innerHTML="";
	    }
	}
	   
    
    for(var i=0;i<lis.length;i++){
      
       lis[i].onclick=function(){
    	   for(var j=0;j<lis.length;j++){
    	        lis[j].className="none";
    	        divs[j].style.display="none";
    	             
    	    }
    	   if(this.id=="youku"){
//    		   var jsonStr = JSON.stringify( result );
//    		   alert(jsonStr);
    		   var imgs=$("#youkuVideo img");
    		   var ps=$("#youkuVideo p");
    		   var as=$(".link1");
    		   for(var i=0;i<4;i++){
    			   imgs[i].src=result.youku[i].picUrl;
    			   as[i].href=result.youku[i].videoUrl;
    			   as[i].target="_blank";
    			   ps[i].innerHTML="<a href=\""+result.youku[i].videoUrl
    			   +"\"  target=\"_blank\">"+result.youku[i].title+"</a>";
    		   }
    		   lis[1].className='select';
       	       divs[1].style.display="block";
    	   }
    	   
    	   if(this.id=="tudou"){
    		   var imgs=$("#tudouVideo img");
    		   var ps=$("#tudouVideo p");
    		   var as=$(".link2");
    		   for(var i=0;i<4;i++){
    			   
    			   imgs[i].src=result.tudou[i].picUrl;
    			   as[i].href=result.tudou[i].videoUrl;
    			   as[i].target="_blank";
    			   ps[i].innerHTML="<a href=\""+result.tudou[i].videoUrl
    			   +"\"  target=\"_blank\">"+result.tudou[i].title+"</a>";
    		   }
    		   lis[2].className='select';
       	       divs[2].style.display="block";
    	   }
    	   
    	   if(this.id=="wangyi"){
    		 
    		   if(result.wangyi==null){
    			   alert("对不起，网易公开课目前还没收录相关视频");
    			   lis[0].className='select';
           	       
    		   }else{
    			   var as=$(".link0");
    			   var imgs=$("#wangyiVideo img");
        		   var ps=$("#wangyiVideo p");
//        		   alert(JSON.stringify(result.wangyi));
        		   for( i=0;i<result.wangyi.length;i++){
//        			   alert(result.wangyi[i].pirUrl);
        			   imgs[i].src=result.wangyi[i].picUrl;
        			   imgs[i].style.display="block";
        			   as[i].href=result.wangyi[i].videoUrl;
        			   as[i].target="_blank";
        			   ps[i].innerHTML="<a href=\""+result.wangyi[i].videoUrl
        			   +"\"  target=\"_blank\">"+result.wangyi[i].title+"</a>";
        		   }
        		   lis[0].className='select';
           	       divs[0].style.display="block";
           	       for(i=result.wangyi.length;i<4;i++){
     			      imgs[i].style.display="none";
     			      ps[i].innerHTML="";
     		       }
    		   }
    		   
    	   }
    	    
//    	    alert(1);
    	    
       };
    }
	
}